#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/11/15 17:37
# @Author  : Virace
# @File    : auth.py
# @Software: PyCharm

from rest_framework.authentication import BaseAuthentication
from rest_framework import exceptions
from test1.models import Users, UserToken
from rest_framework.versioning import URLPathVersioning

class MyAuth(BaseAuthentication):
    """
    验证类
    """

    def authenticate(self, request):
        token = request.GET.get('token')
        token_obj = UserToken.objects.filter(token=token).first()
        if not token_obj:
            raise exceptions.AuthenticationFailed('用户验证失败')

        return token_obj.Users, token_obj

